package com.kede.rest;

import com.kede.annotation.Log;
import com.kede.rest.po.ResourceAreaMapPo;
import com.kede.service.ResourceAreaMapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author Pr.li
* @date 2023-04-22
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "resourceAreaMap管理")
@RequestMapping("/api/resourceAreaMap")
public class ResourceAreaMapController {

    private final ResourceAreaMapService resourceAreaMapService;

    /**
    * 新增resourceAreaMap
    **/
    @PostMapping
    @Log("新增resourceAreaMap")
    @ApiOperation("新增resourceAreaMap")
    @PreAuthorize("@el.check('resourceAreaMap:add')")
    public ResponseEntity<Object> createResourceAreaMap(@RequestBody ResourceAreaMapPo resourceAreaMapPo){
        resourceAreaMapService.setResourceAreaMap(resourceAreaMapPo.getAreaValues(),resourceAreaMapPo.getResourceIds());
        return new ResponseEntity<>("ok",HttpStatus.CREATED);
    }


    /**
     * 取消resourceAreaMap
     **/
    @PostMapping("del")
    @ApiOperation("取消resourceAreaMap")
    @PreAuthorize("@el.check('resourceAreaMap:del')")
    public ResponseEntity<Object> deleteResourceAreaMap(@RequestBody ResourceAreaMapPo resourceAreaMapPo){
        resourceAreaMapService.cancelAreadIdsAndResourceIds(resourceAreaMapPo);
        return new ResponseEntity<>("ok",HttpStatus.CREATED);
    }



}